package com.all.play.mypsm.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.all.play.mypsm.R;
import com.all.play.mypsm.home.bean.HomeResaultBeanData;
import com.all.play.mypsm.utils.Constants;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/3/31.
 */

public class RecomVhAdapter extends BaseAdapter {
    private Context mContext;
    private List<HomeResaultBeanData.ResultBean.RecommendInfoBean> recommend_info;

    public RecomVhAdapter(Context mContext, List<HomeResaultBeanData.ResultBean.RecommendInfoBean> recommend_info) {

        this.mContext = mContext;
        this.recommend_info = recommend_info;
    }

    @Override
    public int getCount() {
        return recommend_info==null?0:recommend_info.size();
    }

    @Override
    public Object getItem(int position) {
        return recommend_info.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView==null){
            vh=new ViewHolder();
            convertView=View.inflate(mContext, R.layout.item_recommend_grid_view,null);
            vh.iv_recommend=convertView.findViewById(R.id.iv_recommend);
            vh.tv_name=convertView.findViewById(R.id.tv_name);
            vh.tv_price=convertView.findViewById(R.id.tv_price);
            convertView.setTag(vh);
        }else{
            vh= (ViewHolder) convertView.getTag();
        }

        HomeResaultBeanData.ResultBean.RecommendInfoBean recommendInfoBean = recommend_info.get(position);
        if(recommendInfoBean!=null){
            String figure = recommendInfoBean.getFigure();
            Glide.with(mContext).load(Constants.BASE_URl_IMAGE+figure).into(vh.iv_recommend);
            vh.tv_name.setText(recommendInfoBean.getName());
            vh.tv_price.setText(recommendInfoBean.getCover_price());
        }


        return convertView;
    }

    static class ViewHolder{
        ImageView iv_recommend;
        TextView tv_name,tv_price;
    }
}
